package com.qhhc.controller;

import com.qhhc.entity.CarInspection;
import com.qhhc.service.CarInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/inspections")
@CrossOrigin(origins = "http://localhost:5173")
public class CarInspectionController {

    @Autowired
    private CarInspectionService carInspectionService;

    /**
     * 获取所有检查记录
     */
    @GetMapping
    public List<CarInspection> getAllInspections() {
        return carInspectionService.getAllInspections();
    }

    /**
     * 根据ID获取检查记录
     */
    @GetMapping("/{inspectionId}")
    public CarInspection getInspectionById(@PathVariable("inspectionId") Long inspectionId) {
        return carInspectionService.getInspectionById(inspectionId);
    }

    /**
     * 根据车辆ID获取检查记录
     */
    @GetMapping("/car/{carId}")
    public List<CarInspection> getInspectionsByCarId(@PathVariable("carId") Long carId) {
        return carInspectionService.getInspectionsByCarId(carId);
    }

    /**
     * 根据检查员获取检查记录
     */
    @GetMapping("/inspector/{inspector}")
    public List<CarInspection> getInspectionsByInspector(@PathVariable("inspector") String inspector) {
        return carInspectionService.getInspectionsByInspector(inspector);
    }

    /**
     * 根据结果获取检查记录
     */
    @GetMapping("/result/{result}")
    public List<CarInspection> getInspectionsByResult(@PathVariable("result") String result) {
        return carInspectionService.getInspectionsByResult(result);
    }

    /**
     * 添加检查记录
     */
    @PostMapping
    public boolean addInspection(@RequestBody CarInspection inspection) {
        return carInspectionService.addInspection(inspection);
    }

    /**
     * 更新检查记录
     */
    @PutMapping
    public boolean updateInspection(@RequestBody CarInspection inspection) {
        return carInspectionService.updateInspection(inspection);
    }

    /**
     * 删除检查记录
     */
    @DeleteMapping("/{inspectionId}")
    public boolean deleteInspection(@PathVariable("inspectionId") Long inspectionId) {
        return carInspectionService.deleteInspection(inspectionId);
    }

    /**
     * 根据车辆ID删除检查记录
     */
    @DeleteMapping("/car/{carId}")
    public boolean deleteInspectionsByCarId(@PathVariable("carId") Long carId) {
        return carInspectionService.deleteInspectionsByCarId(carId);
    }

    /**
     * 条件查询检查记录
     */
    @PostMapping("/search")
    public List<CarInspection> searchInspections(@RequestBody CarInspection inspection) {
        return carInspectionService.getInspectionsByCondition(inspection);
    }
} 